package gui.component;

import database.entity.Contact;
import database.entity.User;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.FlowLayout;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;

/**
 *
 * @author Tom
 */
public class ContactRenderer implements ListCellRenderer<Contact>
{  
    User user;
    
    public ContactRenderer(User user)
    {
        this.user=user;
    }
    
    @Override
    public Component getListCellRendererComponent(JList<? extends Contact> jlist, Contact e, int i, boolean selected, boolean bln1) 
    {
        JPanel pnContact = new JPanel(new BorderLayout());
        JPanel pnLeft = new JPanel(new FlowLayout(FlowLayout.LEFT));
        JPanel pnRight = new JPanel(new FlowLayout(FlowLayout.RIGHT));
        pnContact.add(pnLeft,BorderLayout.WEST);
        pnContact.add(pnRight,BorderLayout.EAST);
        
        //get check
        JCheckBox chbSelected = new JCheckBox();        
        
        JLabel lbContactName = new JLabel(e.ContactName);
        lbContactName.setSize(300,lbContactName.getSize().height);
        JLabel lbContactEmail = new JLabel(e.Email);     
        
        lbContactName.setFont(PreloadedFont.TIMES_NEWS_ROMAN_BOLD_16);
        lbContactEmail.setFont(PreloadedFont.TIMES_NEWS_ROMAN_PLAIN_14);
        
        pnLeft.add(chbSelected);
        pnLeft.add(lbContactName);
        pnLeft.add(lbContactEmail);
        
        if (selected)
        {
            chbSelected.setSelected(true);
            e.selected=true;
            pnLeft.setOpaque(true);
            pnRight.setOpaque(true);
            pnLeft.setBackground(Color.LIGHT_GRAY);
            pnRight.setBackground(Color.LIGHT_GRAY);
        }        
        return pnContact;   
    }
    
}
